//
//  Store.swift
//  物料商行
//
//  Created by HaoDong Hong on 2017/9/2.
//  Copyright © 2017年 HaoDong Hong. All rights reserved.
//

import Foundation



public struct Store {
    static var storeId: Int? {
        get {
            return UserDefaults.standard.integer(forKey: "storeId")
        }
        set {
            UserDefaults.standard.set(newValue, forKey: "storeId")
        }
    }
    static var sessionID: String? {
        get {
            return UserDefaults.standard.string(forKey: "storeSessionID")
        }
        set {
            UserDefaults.standard.set(newValue, forKey: "storeSessionID")
        }
    }
    
    /// 0 代表管理员，1 代表成员
    static var authority: Int? {
        get {
            return UserDefaults.standard.integer(forKey: "authority")
        }
        set {
            UserDefaults.standard.set(newValue, forKey: "authority")
        }
    }
    static var alias: String? {
        get {
            return UserDefaults.standard.string(forKey: "alias")
        }
        set {
            UserDefaults.standard.set(newValue, forKey: "alias")
        }
    }
    static var name: String? {
        get {
            return UserDefaults.standard.string(forKey: "name")
        }
        set {
            UserDefaults.standard.set(newValue, forKey: "name")
        }
    }
    static var address: String? {
        get {
            return UserDefaults.standard.string(forKey: "address")
        }
        set {
            UserDefaults.standard.set(newValue, forKey: "address")
        }
    }
    static var mainBusiness: String? {
        get {
            return UserDefaults.standard.string(forKey: "mainBusiness")
        }
        set {
            UserDefaults.standard.set(newValue, forKey: "mainBusiness")
        }
    }
    static var foundTime: String? {
        get {
            return UserDefaults.standard.string(forKey: "foundTime")
        }
        set {
            UserDefaults.standard.set(newValue, forKey: "foundTime")
        }
    }
    static var license: String? {
        get {
            return UserDefaults.standard.string(forKey: "license")
        }
        set {
            UserDefaults.standard.set(newValue, forKey: "license")
        }
    }
    static var logo: String? {
        get {
            return UserDefaults.standard.string(forKey: "logo")
        }
        set {
            UserDefaults.standard.set(newValue, forKey: "logo")
        }
    }
    static var contact: String? {
        get {
            return UserDefaults.standard.string(forKey: "contact")
        }
        set {
            UserDefaults.standard.set(newValue, forKey: "contact")
        }
    }
    static var phone: String? {
        get {
            return UserDefaults.standard.string(forKey: "phone")
        }
        set {
            UserDefaults.standard.set(newValue, forKey: "phone")
        }
    }
    static var telephone: String? {
        get {
            return UserDefaults.standard.string(forKey: "telephone")
        }
        set {
            UserDefaults.standard.set(newValue, forKey: "telephone")
        }
    }
    static var description: String? {
        get {
            return UserDefaults.standard.string(forKey: "description")
        }
        set {
            UserDefaults.standard.set(newValue, forKey: "description")
        }
    }
    static func clearData() {
        let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
        let imagePath = documentsURL.appendingPathComponent("logo").path
        if FileManager.default.fileExists(atPath: imagePath) {
            do {
                try FileManager.default.removeItem(atPath: imagePath)
            }
            catch let error {
                print(error)
            }
        } else {
            print("file does not exist")
        }

        storeId = nil
        sessionID = nil
        authority = nil
        alias = nil
        name = nil
        address = nil
        mainBusiness = nil
        foundTime = nil
        license = nil
        logo = nil
        contact = nil
        phone = nil
        telephone = nil
        description = nil
        
    }
}
public struct Member {
    var id: Int
    var name: String
    var memberId: String
    var authority: Int
}
